home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume23 / sps2 / part03 < prev    next >
Encoding:
Internet Message Format  |  1991-01-08  |  52.9 KB

  1. Subject:  v23i049:  SPS, a PS replacement, Part03/04
  2. Newsgroups: comp.sources.unix
  3. Approved: rsalz@uunet.UU.NET
  4. X-Checksum-Snefru: e4a9171f aeaafe51 55eb3d16 d2d2dcad
  5.  
  6. Submitted-by: Robert Ward <olsen!robert@uunet.uu.net>
  7. Posting-number: Volume 23, Issue 49
  8. Archive-name: sps2/part03
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then feed it
  12. # into a shell via "sh file" or similar.  To overwrite existing files,
  13. # type "sh file -c".
  14. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  15. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  16. # Contents:  BUG-libkvm Make.4.3+NFS Make.dec3100 Make.sun.2.0
  17. #   Make.sun.3.0 Make.sun.3.2 Make.sun.4.0 Make.sun.4.0+386i
  18. #   Make.sun.4.1 Make.sun4.3.2 Make.ultrix2 Make.ultrix3 RELEASENOTES
  19. #   filecount.c findtty.c flagsetup.c globals1.c hashuid.c
  20. #   initialise.c initsymbols.c mktree.c percentmem.c prcpu.c
  21. #   readstatus.c selectproc.c termwidth.c vmstat.c
  22. # Wrapped by rsalz@papaya.bbn.com on Mon Nov 26 14:03:23 1990
  23. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  24. echo If this archive is complete, you will see the following message:
  25. echo '          "shar: End of archive 3 (of 4)."'
  26. if test -f 'BUG-libkvm' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'BUG-libkvm'\"
  28. else
  29.   echo shar: Extracting \"'BUG-libkvm'\" \(1656 characters\)
  30.   sed "s/^X//" >'BUG-libkvm' <<'END_OF_FILE'
  31. XThere is a bug in kvm_getcmd(3) which occurs when the arguments for a command
  32. Xcontain an '=', or if an '=' in the environment is removed.  In user space,
  33. Xcommand arguments are laid out like this:
  34. X
  35. Xa r g 0 '\0' a r g 1 '\0' ... e n v 1 = e n v '\0' e n v 2 = e n v ...
  36. X
  37. XThe only way to tell where the arguments end and the environment begins is to
  38. Xlook for arguments which contain '=', or environment strings which don't.  Most
  39. Xprograms used to use the first approach.  The libkvm library uses the latter,
  40. Xand gets it wrong if it sees a '=' in any strings before the last string
  41. Xwhich doesn't have one.  The korn shell nulls out some '=' in it's environment,
  42. Xand if you have it, it's the most noticable tickler of this bug.  But even if
  43. Xyou don't, you can tickle it with "vi a=b c".
  44. X
  45. XHere's the fix.  You could probably patch the binary to ignore the
  46. X"&& (argd.cnt == 0)" test, which will cause slightly incorrect results,
  47. Xbut ones a bit closer to the truth.  Just search for "\0=" in the
  48. Xlibrary, and look past it a bit.
  49. X
  50. X*** /tmp/,RCSt1a01687    Wed Sep 28 01:50:36 1988
  51. X--- kvmgetcmd.c    Mon Aug 29 23:23:43 1988
  52. X***************
  53. X*** 141,150 ****
  54. X              if (*cp == '=')
  55. X                  eqseen++;
  56. X              if (*cp-- == '\0') {
  57. X!                 if (eqseen && (argd.cnt == 0)) {
  58. X                      envd.cnt++;
  59. X                      envd.sp = Uvaddr(cp+2);
  60. X                      eqseen = 0;
  61. X                  } else {
  62. X                      argd.cnt++;
  63. X                  }
  64. X--- 141,154 ----
  65. X              if (*cp == '=')
  66. X                  eqseen++;
  67. X              if (*cp-- == '\0') {
  68. X!                 if (eqseen) {
  69. X                      envd.cnt++;
  70. X                      envd.sp = Uvaddr(cp+2);
  71. X                      eqseen = 0;
  72. X+                     if (argd.cnt != 0) {
  73. X+                         envd.cnt += argd.cnt;
  74. X+                         argd.cnt = 0;
  75. X+                     }
  76. X                  } else {
  77. X                      argd.cnt++;
  78. X                  }
  79. END_OF_FILE
  80.   if test 1656 -ne `wc -c <'BUG-libkvm'`; then
  81.     echo shar: \"'BUG-libkvm'\" unpacked with wrong size!
  82.   fi
  83.   # end of 'BUG-libkvm'
  84. fi
  85. if test -f 'Make.4.3+NFS' -a "${1}" != "-c" ; then 
  86.   echo shar: Will not clobber existing file \"'Make.4.3+NFS'\"
  87. else
  88.   echo shar: Extracting \"'Make.4.3+NFS'\" \(976 characters\)
  89.   sed "s/^X//" >'Make.4.3+NFS' <<'END_OF_FILE'
  90. X# Makefile for SPS (Vax 4.3BSD+NFS Version)
  91. X
  92. XPROG    =       sps
  93. XOBJS    =       filecount.o findtty.o flagdecode.o flagsetup.o \
  94. X        getcmd.o getupage.o globals1.o globals2.o hashuid.o \
  95. X        initialise.o initsymbols.o inittty.o main.o mktree.o \
  96. X        needed.o openfiles.o percentmem.o prcmd.o prcpu.o \
  97. X        prheader.o printall.o printproc.o prsummary.o readstatus.o \
  98. X        selectproc.o selecttty.o termwidth.o ttystatus.o waitingfor.o
  99. XINCS    =       sps.h
  100. XCC      =       cc
  101. XCFLAGS  =       -DBSD42 -DBSD43 -DNFS -I/sys
  102. XLIBS    =       -ltermlib
  103. XDIRINSTALL =    /bin
  104. X
  105. Xall:            $(PROG)
  106. X.c.o:
  107. X        $(CC) $(CFLAGS) -c -O -R $<
  108. X    
  109. Xglobals1.o waitingfor.o:
  110. X        $(CC) $(CFLAGS) -c -O $<
  111. X
  112. X$(OBJS):        $(INCS)
  113. X
  114. X$(PROG):        $(OBJS)
  115. X        $(CC) -o $@ $(OBJS) $(LIBS)
  116. X
  117. Xinstall:        $(PROG)
  118. X        strip $(PROG)
  119. X        mv $(PROG) $(DIRINSTALL)/$(PROG)
  120. X        /etc/chown root $(DIRINSTALL)/$(PROG)
  121. X        chgrp kmem $(DIRINSTALL)/$(PROG)
  122. X        chmod 2755 $(DIRINSTALL)/$(PROG)
  123. X
  124. Xlint:
  125. X        lint -x -b $(CFLAGS) *.c
  126. Xclean:
  127. X        rm -f $(OBJS) $(PROG)
  128. END_OF_FILE
  129.   if test 976 -ne `wc -c <'Make.4.3+NFS'`; then
  130.     echo shar: \"'Make.4.3+NFS'\" unpacked with wrong size!
  131.   fi
  132.   # end of 'Make.4.3+NFS'
  133. fi
  134. if test -f 'Make.dec3100' -a "${1}" != "-c" ; then 
  135.   echo shar: Will not clobber existing file \"'Make.dec3100'\"
  136. else
  137.   echo shar: Extracting \"'Make.dec3100'\" \(1005 characters\)
  138.   sed "s/^X//" >'Make.dec3100' <<'END_OF_FILE'
  139. X# Makefile for SPS (Ultrix 2.0 UNIX Version)
  140. X
  141. XPROG    =       sps
  142. XOBJS    =       filecount.o findtty.o flagdecode.o flagsetup.o \
  143. X        getcmd.o getupage.o globals1.o globals2.o hashuid.o \
  144. X        initialise.o initsymbols.o inittty.o main.o mktree.o \
  145. X        needed.o openfiles.o percentmem.o prcmd.o prcpu.o \
  146. X        prheader.o printall.o printproc.o prsummary.o readstatus.o \
  147. X        selectproc.o selecttty.o termwidth.o ttystatus.o waitingfor.o
  148. XINCS    =       sps.h
  149. XCC      =       cc
  150. XCFLAGS  =       -DBSD42 -DULTRIX20 -DULTRIX30 -DVPRINTF -DDEC3100 -I/sys
  151. XLIBS    =       -ltermlib
  152. XDIRINSTALL =    /bin
  153. X
  154. Xall:            $(PROG)
  155. X.c.o:
  156. X        $(CC) $(CFLAGS) -c -g -R $<
  157. X    
  158. Xglobals1.o waitingfor.o:
  159. X        $(CC) $(CFLAGS) -c -g $<
  160. X
  161. X$(OBJS):        $(INCS)
  162. X
  163. X$(PROG):        $(OBJS)
  164. X        $(CC) -o $@ $(OBJS) $(LIBS)
  165. X
  166. Xinstall:        $(PROG)
  167. X        strip $(PROG)
  168. X        mv $(PROG) $(DIRINSTALL)/$(PROG)
  169. X        /etc/chown root $(DIRINSTALL)/$(PROG)
  170. X        chgrp kmem $(DIRINSTALL)/$(PROG)
  171. X        chmod 2755 $(DIRINSTALL)/$(PROG)
  172. X
  173. Xlint:
  174. X        lint -x -b $(CFLAGS) *.c
  175. Xclean:
  176. X        rm -f $(OBJS) $(PROG)
  177. END_OF_FILE
  178.   if test 1005 -ne `wc -c <'Make.dec3100'`; then
  179.     echo shar: \"'Make.dec3100'\" unpacked with wrong size!
  180.   fi
  181.   # end of 'Make.dec3100'
  182. fi
  183. if test -f 'Make.sun.2.0' -a "${1}" != "-c" ; then 
  184.   echo shar: Will not clobber existing file \"'Make.sun.2.0'\"
  185. else
  186.   echo shar: Extracting \"'Make.sun.2.0'\" \(1009 characters\)
  187.   sed "s/^X//" >'Make.sun.2.0' <<'END_OF_FILE'
  188. X# Makefile for SPS (Sun-2, Sun UNIX 4.2 Release 2.x Version)
  189. X
  190. XPROG    =       sps
  191. XOBJS    =       filecount.o findtty.o flagdecode.o flagsetup.o \
  192. X        getcmd.o getupage.o globals1.o globals2.o hashuid.o \
  193. X        initialise.o initsymbols.o inittty.o main.o mktree.o \
  194. X        needed.o openfiles.o percentmem.o prcmd.o prcpu.o \
  195. X        prheader.o printall.o printproc.o prsummary.o readstatus.o \
  196. X        selectproc.o selecttty.o termwidth.o ttystatus.o waitingfor.o
  197. XINCS    =       sps.h
  198. XCC      =       cc
  199. XCFLAGS  =       -DSUN -DBSD42 -DNFS -DNOQUOTA -I/sys
  200. XLIBS    =       -ltermlib
  201. XDIRINSTALL    = /bin
  202. X
  203. Xall:            $(PROG)
  204. X.c.o:
  205. X        $(CC) $(CFLAGS) -c -O -R $<
  206. X    
  207. Xglobals1.o waitingfor.o:
  208. X        $(CC) $(CFLAGS) -c -O $<
  209. X
  210. X$(OBJS):        $(INCS)
  211. X
  212. X$(PROG):        $(OBJS)
  213. X        $(CC) -o $@ $(OBJS) $(LIBS)
  214. X
  215. Xinstall:        $(PROG)
  216. X        strip $(PROG)
  217. X        mv $(PROG) $(DIRINSTALL)/$(PROG)
  218. X        /etc/chown root $(DIRINSTALL)/$(PROG)
  219. X        chgrp kmem $(DIRINSTALL)/$(PROG)
  220. X        chmod 2755 $(DIRINSTALL)/$(PROG)
  221. X
  222. Xlint:
  223. X        lint -x -b $(CFLAGS) *.c $(LIBS)
  224. Xclean:
  225. X        rm -f $(OBJS) $(PROG)
  226. END_OF_FILE
  227.   if test 1009 -ne `wc -c <'Make.sun.2.0'`; then
  228.     echo shar: \"'Make.sun.2.0'\" unpacked with wrong size!
  229.   fi
  230.   # end of 'Make.sun.2.0'
  231. fi
  232. if test -f 'Make.sun.3.0' -a "${1}" != "-c" ; then 
  233.   echo shar: Will not clobber existing file \"'Make.sun.3.0'\"
  234. else
  235.   echo shar: Extracting \"'Make.sun.3.0'\" \(1009 characters\)
  236.   sed "s/^X//" >'Make.sun.3.0' <<'END_OF_FILE'
  237. X# Makefile for SPS (Sun-2 and Sun-3, Sun UNIX 4.2 Release 3.0 Version)
  238. X
  239. XPROG    =       sps
  240. XOBJS    =       filecount.o findtty.o flagdecode.o flagsetup.o \
  241. X        getcmd.o getupage.o globals1.o globals2.o hashuid.o \
  242. X        initialise.o initsymbols.o inittty.o main.o mktree.o \
  243. X        needed.o openfiles.o percentmem.o prcmd.o prcpu.o \
  244. X        prheader.o printall.o printproc.o prsummary.o readstatus.o \
  245. X        selectproc.o selecttty.o termwidth.o ttystatus.o waitingfor.o
  246. XINCS    =       sps.h
  247. XCC      =       cc
  248. XCFLAGS  =       -DSUN -DBSD42 -DNFS -I/sys
  249. XLIBS    =       -ltermlib
  250. XDIRINSTALL    = /bin
  251. X
  252. Xall:            $(PROG)
  253. X.c.o:
  254. X        $(CC) $(CFLAGS) -c -O -R $<
  255. X    
  256. Xglobals1.o waitingfor.o:
  257. X        $(CC) $(CFLAGS) -c -O $<
  258. X
  259. X$(OBJS):        $(INCS)
  260. X
  261. X$(PROG):        $(OBJS)
  262. X        $(CC) -o $@ $(OBJS) $(LIBS)
  263. X
  264. Xinstall:        $(PROG)
  265. X        strip $(PROG)
  266. X        mv $(PROG) $(DIRINSTALL)/$(PROG)
  267. X        /etc/chown root $(DIRINSTALL)/$(PROG)
  268. X        chgrp kmem $(DIRINSTALL)/$(PROG)
  269. X        chmod 2755 $(DIRINSTALL)/$(PROG)
  270. X
  271. Xlint:
  272. X        lint -x -b $(CFLAGS) *.c $(LIBS)
  273. Xclean:
  274. X        rm -f $(OBJS) $(PROG)
  275. END_OF_FILE
  276.   if test 1009 -ne `wc -c <'Make.sun.3.0'`; then
  277.     echo shar: \"'Make.sun.3.0'\" unpacked with wrong size!
  278.   fi
  279.   # end of 'Make.sun.3.0'
  280. fi
  281. if test -f 'Make.sun.3.2' -a "${1}" != "-c" ; then 
  282.   echo shar: Will not clobber existing file \"'Make.sun.3.2'\"
  283. else
  284.   echo shar: Extracting \"'Make.sun.3.2'\" \(1019 characters\)
  285.   sed "s/^X//" >'Make.sun.3.2' <<'END_OF_FILE'
  286. X# Makefile for SPS (Sun-2 and Sun-3, Sun UNIX 4.2 Release 3.x Version)
  287. X
  288. XPROG    =       sps
  289. XOBJS    =       filecount.o findtty.o flagdecode.o flagsetup.o \
  290. X        getcmd.o getupage.o globals1.o globals2.o hashuid.o \
  291. X        initialise.o initsymbols.o inittty.o main.o mktree.o \
  292. X        needed.o openfiles.o percentmem.o prcmd.o prcpu.o \
  293. X        prheader.o printall.o printproc.o prsummary.o readstatus.o \
  294. X        selectproc.o selecttty.o termwidth.o ttystatus.o waitingfor.o
  295. XINCS    =       sps.h
  296. XCC      =       cc
  297. XCFLAGS  =       -DSUN -DBSD42 -DNFS -DVPRINTF -I/sys
  298. XLIBS    =       -ltermlib
  299. XDIRINSTALL    = /bin
  300. X
  301. Xall:            $(PROG)
  302. X.c.o:
  303. X        $(CC) $(CFLAGS) -c -O -R $<
  304. X    
  305. Xglobals1.o waitingfor.o:
  306. X        $(CC) $(CFLAGS) -c -O $<
  307. X
  308. X$(OBJS):        $(INCS)
  309. X
  310. X$(PROG):        $(OBJS)
  311. X        $(CC) -o $@ $(OBJS) $(LIBS)
  312. X
  313. Xinstall:        $(PROG)
  314. X        strip $(PROG)
  315. X        mv $(PROG) $(DIRINSTALL)/$(PROG)
  316. X        /etc/chown root $(DIRINSTALL)/$(PROG)
  317. X        chgrp kmem $(DIRINSTALL)/$(PROG)
  318. X        chmod 2755 $(DIRINSTALL)/$(PROG)
  319. X
  320. Xlint:
  321. X        lint -x -b $(CFLAGS) *.c $(LIBS)
  322. Xclean:
  323. X        rm -f $(OBJS) $(PROG)
  324. END_OF_FILE
  325.   if test 1019 -ne `wc -c <'Make.sun.3.2'`; then
  326.     echo shar: \"'Make.sun.3.2'\" unpacked with wrong size!
  327.   fi
  328.   # end of 'Make.sun.3.2'
  329. fi
  330. if test -f 'Make.sun.4.0' -a "${1}" != "-c" ; then 
  331.   echo shar: Will not clobber existing file \"'Make.sun.4.0'\"
  332. else
  333.   echo shar: Extracting \"'Make.sun.4.0'\" \(1134 characters\)
  334.   sed "s/^X//" >'Make.sun.4.0' <<'END_OF_FILE'
  335. X# Makefile for SPS (Sun-2, Sun-3 and Sun-4, SunOS 4.0 Version)
  336. X
  337. XPROG    =       sps
  338. XOBJS    =       filecount.o findtty.o flagdecode.o flagsetup.o \
  339. X        getcmd.o getupage.o globals1.o globals2.o hashuid.o \
  340. X        initialise.o initsymbols.o inittty.o main.o mktree.o \
  341. X        needed.o openfiles.o percentmem.o prcmd.o prcpu.o \
  342. X        prheader.o printall.o printproc.o prsummary.o readstatus.o \
  343. X        selectproc.o selecttty.o stream.o termwidth.o ttystatus.o \
  344. X        vmstat.o waitingfor.o
  345. XINCS    =       sps.h
  346. XCC      =       cc
  347. XCFLAGS  =       -DSUN -DBSD42 -DNFS -DVPRINTF -DKVM -DSUNOS40 -Isys
  348. XLIBS    =       -ltermlib -lkvm
  349. XDIRINSTALL    = /usr/kvm
  350. X
  351. Xall:            $(PROG)
  352. X.c.o:
  353. X        $(CC) $(CFLAGS) -c -O -R $<
  354. X    
  355. Xglobals1.o stream.o waitingfor.o:
  356. X        $(CC) $(CFLAGS) -c -O $<
  357. X
  358. X$(OBJS):        sys $(INCS)
  359. X
  360. Xsys:
  361. X        -mkdir sys
  362. X        -ln -s /sys/* sys
  363. X        -ln -s /sys/sys sys/h
  364. X
  365. X$(PROG):        $(OBJS)
  366. X        $(CC) -o $@ $(OBJS) $(LIBS)
  367. X
  368. Xinstall:        $(PROG)
  369. X        strip $(PROG)
  370. X        mv $(PROG) $(DIRINSTALL)/$(PROG)
  371. X        /etc/chown root $(DIRINSTALL)/$(PROG)
  372. X        chgrp kmem $(DIRINSTALL)/$(PROG)
  373. X        chmod 2755 $(DIRINSTALL)/$(PROG)
  374. X
  375. Xlint:
  376. X        lint -x -b $(CFLAGS) *.c $(LIBS)
  377. Xclean:
  378. X        rm -f $(OBJS) $(PROG)
  379. END_OF_FILE
  380.   if test 1134 -ne `wc -c <'Make.sun.4.0'`; then
  381.     echo shar: \"'Make.sun.4.0'\" unpacked with wrong size!
  382.   fi
  383.   # end of 'Make.sun.4.0'
  384. fi
  385. if test -f 'Make.sun.4.0+386i' -a "${1}" != "-c" ; then 
  386.   echo shar: Will not clobber existing file \"'Make.sun.4.0+386i'\"
  387. else
  388.   echo shar: Extracting \"'Make.sun.4.0+386i'\" \(1144 characters\)
  389.   sed "s/^X//" >'Make.sun.4.0+386i' <<'END_OF_FILE'
  390. X# Makefile for SPS (Sun-2, Sun-3 and Sun-4, SunOS 4.0 Version)
  391. X
  392. XPROG    =       sps
  393. XOBJS    =       filecount.o findtty.o flagdecode.o flagsetup.o \
  394. X        getcmd.o getupage.o globals1.o globals2.o hashuid.o \
  395. X        initialise.o initsymbols.o inittty.o main.o mktree.o \
  396. X        needed.o openfiles.o percentmem.o prcmd.o prcpu.o \
  397. X        prheader.o printall.o printproc.o prsummary.o readstatus.o \
  398. X        selectproc.o selecttty.o stream.o termwidth.o ttystatus.o \
  399. X        vmstat.o waitingfor.o
  400. XINCS    =       sps.h
  401. XCC      =       cc
  402. XCFLAGS  =       -DSUN -DBSD42 -DNFS -DVPRINTF -DKVM -DSUNOS40 -DSUN386I -Isys
  403. XLIBS    =       -ltermlib -lkvm
  404. XDIRINSTALL    = /usr/kvm
  405. X
  406. Xall:            $(PROG)
  407. X.c.o:
  408. X        $(CC) $(CFLAGS) -c -O -R $<
  409. X    
  410. Xglobals1.o stream.o waitingfor.o:
  411. X        $(CC) $(CFLAGS) -c -O $<
  412. X
  413. X$(OBJS):        sys $(INCS)
  414. X
  415. Xsys:
  416. X        -mkdir sys
  417. X        -ln -s /sys/* sys
  418. X        -ln -s /sys/sys sys/h
  419. X
  420. X$(PROG):        $(OBJS)
  421. X        $(CC) -o $@ $(OBJS) $(LIBS)
  422. X
  423. Xinstall:        $(PROG)
  424. X        strip $(PROG)
  425. X        mv $(PROG) $(DIRINSTALL)/$(PROG)
  426. X        /etc/chown root $(DIRINSTALL)/$(PROG)
  427. X        chgrp kmem $(DIRINSTALL)/$(PROG)
  428. X        chmod 2755 $(DIRINSTALL)/$(PROG)
  429. X
  430. Xlint:
  431. X        lint -x -b $(CFLAGS) *.c $(LIBS)
  432. Xclean:
  433. X        rm -f $(OBJS) $(PROG)
  434. END_OF_FILE
  435.   if test 1144 -ne `wc -c <'Make.sun.4.0+386i'`; then
  436.     echo shar: \"'Make.sun.4.0+386i'\" unpacked with wrong size!
  437.   fi
  438.   # end of 'Make.sun.4.0+386i'
  439. fi
  440. if test -f 'Make.sun.4.1' -a "${1}" != "-c" ; then 
  441.   echo shar: Will not clobber existing file \"'Make.sun.4.1'\"
  442. else
  443.   echo shar: Extracting \"'Make.sun.4.1'\" \(1201 characters\)
  444.   sed "s/^X//" >'Make.sun.4.1' <<'END_OF_FILE'
  445. X# Makefile for SPS (Sun-2, Sun-3 and Sun-4, SunOS 4.1 Version)
  446. X
  447. XPROG    =       sps
  448. XOBJS    =       filecount.o findtty.o flagdecode.o flagsetup.o \
  449. X        getcmd.o getupage.o globals1.o globals2.o hashuid.o \
  450. X        initialise.o initsymbols.o inittty.o main.o mktree.o \
  451. X        needed.o openfiles.o percentmem.o prcmd.o prcpu.o \
  452. X        prheader.o printall.o printproc.o prsummary.o readstatus.o \
  453. X        selectproc.o selecttty.o stream.o termwidth.o ttystatus.o \
  454. X        waitingfor.o
  455. XINCS    =       sps.h
  456. XCC      =       cc
  457. X# You'll need both "-DSUNOS40" and "-DSUNOS41" for SunOS 4.1
  458. XCFLAGS  =    -DSUN -DBSD42 -DNFS -DVPRINTF -DKVM -DSUNOS40 -DSUNOS41 -Isys
  459. XLIBS    =       -ltermlib -lkvm
  460. XDIRINSTALL    = /usr/kvm
  461. X
  462. Xall:            $(PROG)
  463. X.c.o:
  464. X        $(CC) $(CFLAGS) -c -O -R $<
  465. X
  466. Xglobals1.o stream.o waitingfor.o filecount.o:
  467. X        $(CC) $(CFLAGS) -c -O $<
  468. X
  469. X$(OBJS):        sys $(INCS)
  470. X
  471. Xsys:
  472. X        -mkdir sys
  473. X        -ln -s /sys/* sys
  474. X        -ln -s /sys/sys sys/h
  475. X
  476. X$(PROG):        $(OBJS)
  477. X        $(CC) -o $@ $(OBJS) $(LIBS)
  478. X
  479. Xinstall:        $(PROG)
  480. X        strip $(PROG)
  481. X        mv $(PROG) $(DIRINSTALL)/$(PROG)
  482. X        /etc/chown root $(DIRINSTALL)/$(PROG)
  483. X        chgrp kmem $(DIRINSTALL)/$(PROG)
  484. X        chmod 2755 $(DIRINSTALL)/$(PROG)
  485. X
  486. Xlint:
  487. X        lint -x -b $(CFLAGS) *.c $(LIBS)
  488. Xclean:
  489. X        rm -f $(OBJS) $(PROG)
  490. END_OF_FILE
  491.   if test 1201 -ne `wc -c <'Make.sun.4.1'`; then
  492.     echo shar: \"'Make.sun.4.1'\" unpacked with wrong size!
  493.   fi
  494.   # end of 'Make.sun.4.1'
  495. fi
  496. if test -f 'Make.sun4.3.2' -a "${1}" != "-c" ; then 
  497.   echo shar: Will not clobber existing file \"'Make.sun4.3.2'\"
  498. else
  499.   echo shar: Extracting \"'Make.sun4.3.2'\" \(1066 characters\)
  500.   sed "s/^X//" >'Make.sun4.3.2' <<'END_OF_FILE'
  501. X# Makefile for SPS (Sun-4, SunOS Sys 4-3.2 Version)
  502. X
  503. XPROG    =       sps
  504. XOBJS    =       filecount.o findtty.o flagdecode.o flagsetup.o \
  505. X        getcmd.o getupage.o globals1.o globals2.o hashuid.o \
  506. X        initialise.o initsymbols.o inittty.o main.o mktree.o \
  507. X        needed.o openfiles.o percentmem.o prcmd.o prcpu.o \
  508. X        prheader.o printall.o printproc.o prsummary.o readstatus.o \
  509. X        selectproc.o selecttty.o termwidth.o ttystatus.o waitingfor.o
  510. XINCS    =       sps.h
  511. XCC      =       cc
  512. XCFLAGS  =       -DSUN -DBSD42 -DNFS -DVPRINTF -Isys
  513. XLIBS    =       -ltermlib
  514. XDIRINSTALL    = /bin
  515. X
  516. Xall:            $(PROG)
  517. X.c.o:
  518. X        $(CC) $(CFLAGS) -c -O -R $<
  519. X    
  520. Xglobals1.o waitingfor.o:
  521. X        $(CC) $(CFLAGS) -c -O $<
  522. X
  523. X$(OBJS):        sys $(INCS)
  524. X
  525. Xsys:
  526. X        -mkdir sys
  527. X        -ln -s /sys/* sys
  528. X        -ln -s /sys/sys sys/h
  529. X
  530. X$(PROG):        $(OBJS)
  531. X        $(CC) -o $@ $(OBJS) $(LIBS)
  532. X
  533. Xinstall:        $(PROG)
  534. X        strip $(PROG)
  535. X        mv $(PROG) $(DIRINSTALL)/$(PROG)
  536. X        /etc/chown root $(DIRINSTALL)/$(PROG)
  537. X        chgrp kmem $(DIRINSTALL)/$(PROG)
  538. X        chmod 2755 $(DIRINSTALL)/$(PROG)
  539. X
  540. Xlint:
  541. X        lint -x -b $(CFLAGS) *.c $(LIBS)
  542. Xclean:
  543. X        rm -f $(OBJS) $(PROG)
  544. END_OF_FILE
  545.   if test 1066 -ne `wc -c <'Make.sun4.3.2'`; then
  546.     echo shar: \"'Make.sun4.3.2'\" unpacked with wrong size!
  547.   fi
  548.   # end of 'Make.sun4.3.2'
  549. fi
  550. if test -f 'Make.ultrix2' -a "${1}" != "-c" ; then 
  551.   echo shar: Will not clobber existing file \"'Make.ultrix2'\"
  552. else
  553.   echo shar: Extracting \"'Make.ultrix2'\" \(984 characters\)
  554.   sed "s/^X//" >'Make.ultrix2' <<'END_OF_FILE'
  555. X# Makefile for SPS (Ultrix 2.0 UNIX Version)
  556. X
  557. XPROG    =       sps
  558. XOBJS    =       filecount.o findtty.o flagdecode.o flagsetup.o \
  559. X        getcmd.o getupage.o globals1.o globals2.o hashuid.o \
  560. X        initialise.o initsymbols.o inittty.o main.o mktree.o \
  561. X        needed.o openfiles.o percentmem.o prcmd.o prcpu.o \
  562. X        prheader.o printall.o printproc.o prsummary.o readstatus.o \
  563. X        selectproc.o selecttty.o termwidth.o ttystatus.o waitingfor.o
  564. XINCS    =       sps.h
  565. XCC      =       cc
  566. XCFLAGS  =       -DBSD42 -DULTRIX20 -DVPRINTF -I/sys
  567. XLIBS    =       -ltermlib
  568. XDIRINSTALL =    /bin
  569. X
  570. Xall:            $(PROG)
  571. X.c.o:
  572. X        $(CC) $(CFLAGS) -c -O -R $<
  573. X    
  574. Xglobals1.o waitingfor.o:
  575. X        $(CC) $(CFLAGS) -c -O $<
  576. X
  577. X$(OBJS):        $(INCS)
  578. X
  579. X$(PROG):        $(OBJS)
  580. X        $(CC) -o $@ $(OBJS) $(LIBS)
  581. X
  582. Xinstall:        $(PROG)
  583. X        strip $(PROG)
  584. X        mv $(PROG) $(DIRINSTALL)/$(PROG)
  585. X        /etc/chown root $(DIRINSTALL)/$(PROG)
  586. X        chgrp kmem $(DIRINSTALL)/$(PROG)
  587. X        chmod 2755 $(DIRINSTALL)/$(PROG)
  588. X
  589. Xlint:
  590. X        lint -x -b $(CFLAGS) *.c
  591. Xclean:
  592. X        rm -f $(OBJS) $(PROG)
  593. END_OF_FILE
  594.   if test 984 -ne `wc -c <'Make.ultrix2'`; then
  595.     echo shar: \"'Make.ultrix2'\" unpacked with wrong size!
  596.   fi
  597.   # end of 'Make.ultrix2'
  598. fi
  599. if test -f 'Make.ultrix3' -a "${1}" != "-c" ; then 
  600.   echo shar: Will not clobber existing file \"'Make.ultrix3'\"
  601. else
  602.   echo shar: Extracting \"'Make.ultrix3'\" \(995 characters\)
  603.   sed "s/^X//" >'Make.ultrix3' <<'END_OF_FILE'
  604. X# Makefile for SPS (Ultrix 2.0 UNIX Version)
  605. X
  606. XPROG    =       sps
  607. XOBJS    =       filecount.o findtty.o flagdecode.o flagsetup.o \
  608. X        getcmd.o getupage.o globals1.o globals2.o hashuid.o \
  609. X        initialise.o initsymbols.o inittty.o main.o mktree.o \
  610. X        needed.o openfiles.o percentmem.o prcmd.o prcpu.o \
  611. X        prheader.o printall.o printproc.o prsummary.o readstatus.o \
  612. X        selectproc.o selecttty.o termwidth.o ttystatus.o waitingfor.o
  613. XINCS    =       sps.h
  614. XCC      =       cc
  615. XCFLAGS  =       -DBSD42 -DULTRIX20 -DULTRIX30 -DVPRINTF -I/sys
  616. XLIBS    =       -ltermlib
  617. XDIRINSTALL =    /bin
  618. X
  619. Xall:            $(PROG)
  620. X.c.o:
  621. X        $(CC) $(CFLAGS) -c -O -R $<
  622. X    
  623. Xglobals1.o waitingfor.o:
  624. X        $(CC) $(CFLAGS) -c -O $<
  625. X
  626. X$(OBJS):        $(INCS)
  627. X
  628. X$(PROG):        $(OBJS)
  629. X        $(CC) -o $@ $(OBJS) $(LIBS)
  630. X
  631. Xinstall:        $(PROG)
  632. X        strip $(PROG)
  633. X        mv $(PROG) $(DIRINSTALL)/$(PROG)
  634. X        /etc/chown root $(DIRINSTALL)/$(PROG)
  635. X        chgrp kmem $(DIRINSTALL)/$(PROG)
  636. X        chmod 2755 $(DIRINSTALL)/$(PROG)
  637. X
  638. Xlint:
  639. X        lint -x -b $(CFLAGS) *.c
  640. Xclean:
  641. X        rm -f $(OBJS) $(PROG)
  642. END_OF_FILE
  643.   if test 995 -ne `wc -c <'Make.ultrix3'`; then
  644.     echo shar: \"'Make.ultrix3'\" unpacked with wrong size!
  645.   fi
  646.   # end of 'Make.ultrix3'
  647. fi
  648. if test -f 'RELEASENOTES' -a "${1}" != "-c" ; then 
  649.   echo shar: Will not clobber existing file \"'RELEASENOTES'\"
  650. else
  651.   echo shar: Extracting \"'RELEASENOTES'\" \(3510 characters\)
  652.   sed "s/^X//" >'RELEASENOTES' <<'END_OF_FILE'
  653. X        NEW  RELEASE  OF  SPS
  654. X        =====================
  655. X
  656. X
  657. XThe files in this directory represent a major new release of the SPS
  658. Xprogram.  One or two minor bugs have been corrected but, more
  659. Ximportantly, SPS has now been ported to run under the SunOS 4.0, 4.1 and
  660. XUltrix 2.x and 3.x operating systems.
  661. X
  662. X
  663. XGratitude and heart-felt thanks for these achievments should be
  664. Xdirected to Rob Lehman (and others?) at CUCCA, Charlie Kim
  665. X<cck@cunixc.cc.columbia.edu> at CUCCA and, in particular, to Alexander
  666. XDupuy <dupuy@ncs.columbia.edu> at the Columbia C.S. Dept.  Rob Lehman
  667. Xadded the Ultrix 2.x support. Charlie Kim and Alexander Dupuy
  668. Ximplemented the SunOS 4.0 support and Alexander added support for the
  669. XNFS additions as well as incorporating general improvements to the code.
  670. XSakari Jalovaara <sja@sirius.hut.fi> at the Helsinki University of Technology
  671. XComputing Centre added the support for SunOS4.1.
  672. X
  673. X
  674. XThis release of SPS includes support for all(?) systems previously
  675. Xsupported, although it has not been tested under 4.1 or 4.2bsd, or Sun 4.2
  676. XUNIX Release 2.x.  New systems supported include Ultrix 2.x and SunOS 4.0
  677. Xand SunOS 4.1.  The support for Sun 2.x and 3.x releases has been
  678. Ximproved.  Support for the DEC 3100 has been included, as yet incomplete.
  679. X
  680. XMinor fixes include:
  681. X    One additional option [-c], identical to the ps(1) -c option,
  682. X    has been added.
  683. X    The code to warn if the passwd file is older than the info file
  684. X    has been ifdef'ed out since this caused more grief than
  685. X    benefit.  The old code may be reactivated by a -DWARNPASSWD
  686. X    compiler flag.
  687. X    Under SunOS, a status of itty?? indicates a process that is waiting
  688. X    to read or write to an iconified window.
  689. X
  690. X
  691. XFor SunOS 4.x users:
  692. X    One additional file is included in this distribution, BUG-libkvm,
  693. X    containing a (source-only, sorry) patch to fix a bug in the libkvm
  694. X    library where the command arguments for the ksh (or "vi a=b c", for
  695. X    that matter) are returned incorrectly buy kvm_getcmd(3).
  696. X
  697. XFor DecStation 3100 users:
  698. X    The code that mimics the virtual to physical address translation is
  699. X    incomplete.  Upage information is accessed correctly but not the
  700. X    command line arguments.  If anyone knows how to make this code work,
  701. X    please contact me.
  702. X
  703. X
  704. XBuilding and installing SPS works much like it did before, only now there are
  705. Xeven more Makefiles to choose from:
  706. X    Makefile.4.1        Standard 4.1bsd for Vax
  707. X    Makefile.4.2        Standard 4.2bsd, Ultrix 1.x for Vax
  708. X    Makefile.4.3        Standard 4.3bsd (or 4.3-tahoe) for Vax
  709. X    Makefile.4.3+NFS    4.3bsd+NFS from Wisconsin (Mt. Xinu?, others?)
  710. X    Makefile.dec3100    DECStation 3100 + Ultrix 3.0 (incomplete)
  711. X    Makefile.sun.2.0    Sun 4.2 UNIX Release 2.0 - 2.2 for Sun-2
  712. X    Makefile.sun.3.0    Sun 4.2 UNIX Release 3.0 for Sun-2, Sun-3
  713. X    Makefile.sun.3.2    Sun 4.2 UNIX Release 3.2 for Sun-2, Sun-3
  714. X    Makefile.sun.4.0    SunOS 4.0 for Sun-2, Sun-3, Sun-4
  715. X    Makefile.sun.4.0+386i    SunOS 4.0 for Sun 386i
  716. X    Makefile.sun.4.1    SunOS 4.1 for Sun-2, Sun-3, Sun-4
  717. X    Makefile.sun4.3.2    SunOS Sys 4-3.2 for Sun-4
  718. X    Makefile.ultrix.2.0    DEC Ultrix 2.0 - 2.2
  719. X    Makefile.ultrix.3.0    DEC Ultrix 3.0
  720. X
  721. X
  722. X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  723. X    J. Robert Ward,
  724. X    Olsen & Associates, Seefeldstrasse 233, CH-8008 Zuerich, Switzerland
  725. X
  726. XTel.:   +41 1 552224     Fax: +41 1 552282    Telex: 816656
  727. XEmail:  robert@olsen.uu.ch              Uucp:  uunet!chx400!olsen!robert
  728. XX.400:  s=robert/ou=olsen/o=uucp/p=switch/a=arcom/c=ch
  729. X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  730. END_OF_FILE
  731.   if test 3510 -ne `wc -c <'RELEASENOTES'`; then
  732.     echo shar: \"'RELEASENOTES'\" unpacked with wrong size!
  733.   fi
  734.   # end of 'RELEASENOTES'
  735. fi
  736. if test -f 'filecount.c' -a "${1}" != "-c" ; then 
  737.   echo shar: Will not clobber existing file \"'filecount.c'\"
  738. else
  739.   echo shar: Extracting \"'filecount.c'\" \(1585 characters\)
  740.   sed "s/^X//" >'filecount.c' <<'END_OF_FILE'
  741. X# ifndef lint
  742. Xstatic char SccsId[] =  "@(#)filecount.c    1.2\t7/4/90" ;
  743. X# endif
  744. X
  745. X# include       "sps.h"
  746. X
  747. X/* FILECOUNT - Counts the # open files for the current process */
  748. Xfilecount ( p )
  749. X
  750. Xstruct process         *p ;
  751. X
  752. X{
  753. X    register int            i ;
  754. X    register struct file    **f ;
  755. X    register int            count ;
  756. X    extern union userstate  User ;
  757. X# ifdef SUNOS41
  758. X    /*
  759. X     * The open file list is in User.u_us.u_ofile_arr
  760. X     * if User.u_us.u_ofile points to it; otherwise we'll have
  761. X     * do it the hard way by reading the list from kmem.
  762. X     *
  763. X     * Read the comment to u_ofile in /usr/include/sys/user.h.
  764. X     */
  765. X
  766. X    int            len ;
  767. X    static char        *files = 0 ;
  768. X    static int         files_len = 0 ;
  769. X    extern char        *getcore () ;
  770. X# endif SUNOS41
  771. X
  772. X
  773. X# ifdef SUNOS41
  774. X
  775. X#  ifndef offsetof
  776. X#   define offsetof(type,member)    ((long) &(((type *) 0)->member))
  777. X#  endif offsetof
  778. X
  779. X    if ( (long) User.u_us.u_ofile ==
  780. X        (long) p->pr_p.p_uarea + offsetof(struct user, u_ofile_arr[0]) )
  781. X        f = &User.u_us.u_ofile_arr[ 0 ] ;
  782. X    else
  783. X    {
  784. X        len = User.u_us.u_lastfile * sizeof (struct file *) ;
  785. X        if (len <= 0)
  786. X            return 0;
  787. X        if (files == 0 || len < files_len)
  788. X        {
  789. X            if (files != 0)
  790. X                free (files) ;
  791. X            files = (char *) getcore(len) ;
  792. X            files_len = len ;
  793. X        }
  794. X        if ( getkmem( (long)User.u_us.u_ofile, (char *)files, len)
  795. X        != len )
  796. X            return 0 ;
  797. X        f = (struct file **)files ;
  798. X    }
  799. X    count = 0 ;
  800. X    for ( i = 0 ; i < User.u_us.u_lastfile ; i++ )
  801. X        if ( *f++ )
  802. X            count++ ;
  803. X    return ( count ) ;
  804. X# else SUNOS41
  805. X    count = 0 ;
  806. X    for ( i = 0, f = User.u_us.u_ofile ; i < NOFILE ; i++ )
  807. X        if ( *f++ )
  808. X            count++ ;
  809. X    return ( count ) ;
  810. X# endif SUNOS41
  811. X}
  812. END_OF_FILE
  813.   if test 1585 -ne `wc -c <'filecount.c'`; then
  814.     echo shar: \"'filecount.c'\" unpacked with wrong size!
  815.   fi
  816.   # end of 'filecount.c'
  817. fi
  818. if test -f 'findtty.c' -a "${1}" != "-c" ; then 
  819.   echo shar: Will not clobber existing file \"'findtty.c'\"
  820. else
  821.   echo shar: Extracting \"'findtty.c'\" \(1324 characters\)
  822.   sed "s/^X//" >'findtty.c' <<'END_OF_FILE'
  823. X# ifndef lint
  824. Xstatic char SccsId[] =  "@(#)findtty.c    1.4\t8/6/90" ;
  825. X# endif
  826. X
  827. X# include       "sps.h"
  828. X# include       <h/ioctl.h>
  829. X# ifdef SUNOS40
  830. X# include       <h/stream.h>
  831. X# else
  832. X# include       <h/tty.h>
  833. X# endif
  834. X# ifdef SUNOS41
  835. X# include    <h/session.h>
  836. X# endif
  837. X
  838. X/* FINDTTY - Attempts to determine to which tty a process is connected */
  839. Xstruct ttyline  *findtty ( p )
  840. X
  841. Xregister struct process         *p ;
  842. X
  843. X{
  844. X    register struct ttyline *lp ;
  845. X    extern struct info      Info ;
  846. X    extern struct ttyline   Notty ;
  847. X# ifdef SUNOS41
  848. X    struct sess        *s ;
  849. X    extern struct sess    *find_session () ;
  850. X# else
  851. X    extern union userstate  User ;
  852. X# endif SUNOS41
  853. X
  854. X
  855. X# ifdef SUNOS41
  856. X    if ( !p->pr_p.p_pgrp || !p->pr_p.p_sessp )
  857. X        return ( &Notty ) ;
  858. X    s = find_session( p->pr_p.p_sessp ) ;
  859. X    if ( s == 0 || s->s_ttyp == 0 )
  860. X        return &Notty;
  861. X    for ( lp = Info.i_ttyline ; lp->l_name[0] ; lp++ )
  862. X        if ( lp->l_dev == s->s_ttyd )
  863. X            return ( lp ) ;
  864. X    /* Kludge from outer space    ++sja */
  865. X    if ( s->s_ttyd == 256 )
  866. X        return &Info.i_ttyline[0] ;
  867. X    return ( &Notty ) ;
  868. X# else
  869. X#  ifdef ULTRIX30
  870. X    if ( !p->pr_p.p_pgrp || !p->pr_p.p_ttyp )
  871. X#  else
  872. X    if ( !p->pr_p.p_pgrp || !User.u_us.u_ttyp )
  873. X#  endif
  874. X        return ( &Notty ) ;
  875. X    for ( lp = Info.i_ttyline ; lp->l_name[0] ; lp++ )
  876. X        if ( lp->l_dev == User.u_us.u_ttyd )
  877. X            return ( lp ) ;
  878. X    return ( &Notty ) ;
  879. X#endif SUNOS41
  880. X}
  881. END_OF_FILE
  882.   if test 1324 -ne `wc -c <'findtty.c'`; then
  883.     echo shar: \"'findtty.c'\" unpacked with wrong size!
  884.   fi
  885.   # end of 'findtty.c'
  886. fi
  887. if test -f 'flagsetup.c' -a "${1}" != "-c" ; then 
  888.   echo shar: Will not clobber existing file \"'flagsetup.c'\"
  889. else
  890.   echo shar: Extracting \"'flagsetup.c'\" \(2342 characters\)
  891.   sed "s/^X//" >'flagsetup.c' <<'END_OF_FILE'
  892. X# ifndef lint
  893. Xstatic char SccsId[] =  "@(#)flagsetup.c    1.1\t10/1/88" ;
  894. X# endif
  895. X
  896. X# include       "sps.h"
  897. X# include       "flags.h"
  898. X# include       <h/ioctl.h>
  899. X# ifdef SUNOS40
  900. X# include       <h/stream.h>
  901. X# endif
  902. X# include       <h/tty.h>
  903. X
  904. X/*
  905. X** FLAGSETUP - Replaces any users or processes specified by flagdecode()
  906. X** with numerical equivalents. The lists are terminated by negative values.
  907. X** or null pointers. Ttystatus() must have been previously called to
  908. X** initialise the Info structure with chaos tty values.
  909. X*/
  910. Xflagsetup ()
  911. X{
  912. X    register union flaglist *fp ;
  913. X    register char           *chp ;
  914. X    register int            i ;
  915. X    register struct ttyline *lp ;
  916. X    int                     found ;
  917. X    extern struct flags     Flg ;
  918. X    extern struct info      Info ;
  919. X
  920. X    /* Look for specified users */
  921. X    if ( Flg.flg_U )                
  922. X    {
  923. X        if ( !Flg.flg_Ulist->f_chp )
  924. X            prexit( "sps - User name was expected after -u flag\n");
  925. X        for ( fp = Flg.flg_Ulist ; chp = fp->f_chp ; fp++ )
  926. X        {
  927. X            found = 0 ;
  928. X            for ( i = 0 ; i < MAXUSERS ; i++ )
  929. X                if ( !strncmp( chp, Info.i_hnames[i].h_uname,
  930. X                    UNAMELEN ) )
  931. X                {
  932. X                    fp->f_uid = Info.i_hnames[i].h_uid ;
  933. X                    found = 1 ;
  934. X                    break ;
  935. X                }
  936. X            if ( !found )
  937. X                prexit( "sps - Unknown user: %s\n", chp ) ;
  938. X        }
  939. X        fp->f_uid = -1 ;
  940. X    }
  941. X    /* Look for specified process ids */
  942. X    if ( Flg.flg_P )                
  943. X    {
  944. X        if ( !Flg.flg_Plist->f_chp )
  945. X            prexit(
  946. X                 "sps - Process id was expected after -p flag\n" ) ;
  947. X        for ( fp = Flg.flg_Plist ; chp = fp->f_chp ; fp++ )
  948. X        {
  949. X            if ( chp[0] < '0' || chp[0] > '9' )
  950. X                prexit( "sps - Bad process id: %s\n", chp ) ;
  951. X            fp->f_pid = atoi( chp ) ;
  952. X        }
  953. X        fp->f_pid = -1 ;
  954. X    }
  955. X    /* Look for specified ttys */
  956. X    if ( !Flg.flg_T )               
  957. X        return ;
  958. X    if ( !Flg.flg_Tlist->f_chp )
  959. X        prexit( "sps - Tty name was expected after -t flag\n" ) ;
  960. X    for ( fp = Flg.flg_Tlist ; chp = fp->f_chp ; fp++ )
  961. X    {       /* Under VMUNIX, all ttys have two character names.
  962. X           Thus, a flag of the form `t 8' should be expanded to
  963. X           become `t 08'. */
  964. X        if ( !chp[1] )
  965. X            chp[1] = chp[0], chp[0] = '0' ;
  966. X        found = 0 ;
  967. X        for ( lp = Info.i_ttyline ; lp->l_name[0] ; lp++ )
  968. X            if ( !strncmp( chp, lp->l_name, 2 ) )
  969. X            {
  970. X                fp->f_ttyline = lp ;
  971. X                found = 1 ;
  972. X                break ;
  973. X            }
  974. X        if ( !found )
  975. X            prexit( "sps - Unknown tty name: %.2s\n", chp ) ;
  976. X    }
  977. X    fp->f_ttyline = (struct ttyline*)0 ;
  978. X}
  979. END_OF_FILE
  980.   if test 2342 -ne `wc -c <'flagsetup.c'`; then
  981.     echo shar: \"'flagsetup.c'\" unpacked with wrong size!
  982.   fi
  983.   # end of 'flagsetup.c'
  984. fi
  985. if test -f 'globals1.c' -a "${1}" != "-c" ; then 
  986.   echo shar: Will not clobber existing file \"'globals1.c'\"
  987. else
  988.   echo shar: Extracting \"'globals1.c'\" \(945 characters\)
  989.   sed "s/^X//" >'globals1.c' <<'END_OF_FILE'
  990. X# ifndef lint
  991. Xstatic char SccsId[] =  "@(#)globals1.c    1.1\t10/1/88" ;
  992. X# endif
  993. X
  994. X# include       "sps.h"
  995. X# include       "flags.h"
  996. X# ifdef KVM
  997. X# include       <kvm.h>
  998. X# endif
  999. X
  1000. X/* Read/Write Variables global to the code of sps */
  1001. X
  1002. Xstruct info                     Info ;          /* Information structure */
  1003. X
  1004. Xstruct flags                    Flg ;           /* Flag options */
  1005. X
  1006. Xstruct summary                  Summary ;       /* Summary of processes */
  1007. X
  1008. Xunion  userstate                User ;          /* Upage of one process */
  1009. X
  1010. X# ifdef KVM
  1011. Xkvm_t                          *Flkvm ;         /* Kernel VM descriptor */
  1012. X# else
  1013. Xint                             Flmem, Flkmem, Flswap ; /* File descriptors */
  1014. X# endif
  1015. X
  1016. Xunsigned                        Termwidth ;     /* Width of output device */
  1017. X
  1018. Xshort                           Lastpgrp ;      /* Last process pgrp printed */
  1019. X
  1020. Xshort                           Lastuid ;       /* Last process uid printed */
  1021. END_OF_FILE
  1022.   if test 945 -ne `wc -c <'globals1.c'`; then
  1023.     echo shar: \"'globals1.c'\" unpacked with wrong size!
  1024.   fi
  1025.   # end of 'globals1.c'
  1026. fi
  1027. if test -f 'hashuid.c' -a "${1}" != "-c" ; then 
  1028.   echo shar: Will not clobber existing file \"'hashuid.c'\"
  1029. else
  1030.   echo shar: Extracting \"'hashuid.c'\" \(1515 characters\)
  1031.   sed "s/^X//" >'hashuid.c' <<'END_OF_FILE'
  1032. X# ifndef lint
  1033. Xstatic char SccsId[] =  "@(#)hashuid.c    1.1\t10/1/88" ;
  1034. X# endif
  1035. X
  1036. X# include       "sps.h"
  1037. X
  1038. X/* The hashing functions themselves ... */
  1039. X# define        HASHFN1( a )            (((unsigned)(a)*91 + 17) % MAXUSERS)
  1040. X# define        HASHFN2( a )            (((unsigned)(a) + 47) % MAXUSERS)
  1041. X
  1042. X/*
  1043. X** HASHUID - Returns a pointer to a slot in the hash table that corresponds
  1044. X** to the hash table entry for `uid'. It returns a null pointer if there is
  1045. X** no such slot.
  1046. X*/
  1047. Xstruct hashtab  *hashuid ( uid )
  1048. X
  1049. Xint                             uid ;
  1050. X
  1051. X{
  1052. X    register struct hashtab *hp ;
  1053. X    register int            i ;
  1054. X    register int            j ;
  1055. X    extern struct info      Info ;
  1056. X
  1057. X    j = HASHFN1( uid ) ;
  1058. X    for ( i = 0 ; i < MAXUSERS ; i++ )
  1059. X    {
  1060. X        hp = &Info.i_hnames[ j ] ;
  1061. X        if ( !hp->h_uname[0] )
  1062. X            return ( (struct hashtab*)0 ) ;
  1063. X        if ( hp->h_uid == uid )
  1064. X            return ( hp ) ;
  1065. X        j = HASHFN2( j ) ;
  1066. X    }
  1067. X    return ( (struct hashtab*)0 ) ;
  1068. X}
  1069. X
  1070. X/*
  1071. X** HASHNEXT - Returns a pointer to the next slot in the hash table that
  1072. X** may be use for storing information for `uid'. It returns a null pointer
  1073. X** if there are no more free slots available.
  1074. X*/
  1075. Xstruct hashtab  *hashnext ( uid )
  1076. X
  1077. Xint                             uid ;
  1078. X
  1079. X{
  1080. X    register struct hashtab *hp ;
  1081. X    register int            i ;
  1082. X    register int            j ;
  1083. X    extern struct info      Info ;
  1084. X
  1085. X    j = HASHFN1( uid ) ;
  1086. X    for ( i = 0 ; i < MAXUSERS ; i++ )
  1087. X    {
  1088. X        hp = &Info.i_hnames[ j ] ;
  1089. X        if ( !hp->h_uname[0] )
  1090. X            return ( hp ) ;
  1091. X        j = HASHFN2( j ) ;
  1092. X    }
  1093. X    return ( (struct hashtab*)0 ) ;
  1094. X}
  1095. END_OF_FILE
  1096.   if test 1515 -ne `wc -c <'hashuid.c'`; then
  1097.     echo shar: \"'hashuid.c'\" unpacked with wrong size!
  1098.   fi
  1099.   # end of 'hashuid.c'
  1100. fi
  1101. if test -f 'initialise.c' -a "${1}" != "-c" ; then 
  1102.   echo shar: Will not clobber existing file \"'initialise.c'\"
  1103. else
  1104.   echo shar: Extracting \"'initialise.c'\" \(1986 characters\)
  1105.   sed "s/^X//" >'initialise.c' <<'END_OF_FILE'
  1106. X# ifndef lint
  1107. Xstatic char SccsId[] =  "@(#)initialise.c    1.1\t10/1/88" ;
  1108. X# endif
  1109. X
  1110. X# include       "sps.h"
  1111. X# include       "flags.h"
  1112. X# include       <pwd.h>
  1113. X# include       <stdio.h>
  1114. X
  1115. X/*
  1116. X** INITIALISE - Called to reset the `Info' structure with new kernel
  1117. X** addresses and user and tty information.
  1118. X*/
  1119. Xinitialise ()
  1120. X{
  1121. X    register FILE           *fd ;
  1122. X    char                    *fileinfo ;
  1123. X    extern struct flags     Flg ;
  1124. X    extern struct info      Info ;
  1125. X    FILE                    *fopen() ;
  1126. X
  1127. X    fileinfo = Flg.flg_j ? Flg.flg_j : FILE_INFO ;
  1128. X    /* Read kernel addresses */
  1129. X    initsymbols() ;                 
  1130. X    /* Read user names */
  1131. X    initusers() ;                   
  1132. X    (void)umask( ~0644 ) ;          
  1133. X    if ( !(fd = fopen( fileinfo, "w" )) )
  1134. X    {
  1135. X        fprintf( stderr, "sps - Can't create info file %s", fileinfo ) ;
  1136. X        sysperror() ;
  1137. X    }
  1138. X    /* Find tty addresses */
  1139. X    inittty() ;                     
  1140. X    if ( fwrite( (char*)&Info, sizeof( struct info ), 1, fd ) != 1 )
  1141. X    {
  1142. X        fprintf( stderr, "sps - Can't write info file %s", fileinfo ) ;
  1143. X        sysperror() ;
  1144. X        exit( 1 ) ;
  1145. X    }
  1146. X    (void)fclose( fd ) ;
  1147. X    printf( "sps is initialised\n" ) ;
  1148. X}
  1149. X
  1150. X/* INITUSERS - Read the passwd file and fill in the user name arrays */
  1151. Xinitusers ()
  1152. X{
  1153. X    register struct passwd  *pw ;
  1154. X    register struct hashtab *hp ;
  1155. X    struct passwd           *getpwent() ;
  1156. X    char                    *strncpy() ;
  1157. X    struct hashtab          *hashuid(), *hashnext() ;
  1158. X
  1159. X    while ( pw = getpwent() )
  1160. X    {       /* For each user in the passwd file, first see if that uid
  1161. X           has been already allocated in the hash table. */
  1162. X        if ( hp = hashuid( pw->pw_uid ) )
  1163. X        {
  1164. X            fprintf( stderr,
  1165. X           "sps - Names %s and %s conflict in passwd file for uid %d\n",
  1166. X                hp->h_uname, pw->pw_name, pw->pw_uid ) ;
  1167. X            continue ;
  1168. X        }
  1169. X        /* Try to find a free slot in the hash table and fill it. */
  1170. X        if ( !(hp = hashnext( pw->pw_uid )) )
  1171. X            prexit( "sps - Too many users in passwd file\n" ) ;
  1172. X        hp->h_uid = pw->pw_uid ;
  1173. X        (void)strncpy( hp->h_uname, pw->pw_name, UNAMELEN ) ;
  1174. X    }
  1175. X    (void)endpwent() ;
  1176. X}
  1177. END_OF_FILE
  1178.   if test 1986 -ne `wc -c <'initialise.c'`; then
  1179.     echo shar: \"'initialise.c'\" unpacked with wrong size!
  1180.   fi
  1181.   # end of 'initialise.c'
  1182. fi
  1183. if test -f 'initsymbols.c' -a "${1}" != "-c" ; then 
  1184.   echo shar: Will not clobber existing file \"'initsymbols.c'\"
  1185. else
  1186.   echo shar: Extracting \"'initsymbols.c'\" \(3515 characters\)
  1187.   sed "s/^X//" >'initsymbols.c' <<'END_OF_FILE'
  1188. X# ifndef lint
  1189. Xstatic char SccsId[] =    "@(#)initsymbols.c    1.4\t8/6/90" ;
  1190. X# endif lint
  1191. X
  1192. X# include       "sps.h"
  1193. X# include       "flags.h"
  1194. X# ifdef BSD42
  1195. X#  include       <sys/file.h>
  1196. X# endif BSD42
  1197. X# ifdef KVM
  1198. X#  include       <kvm.h>
  1199. X# endif KVM
  1200. X# include       <nlist.h>
  1201. X# include       <stdio.h>
  1202. X
  1203. X/* INITSYMBOLS - Reads kmem values into the Info structure */
  1204. X/*
  1205. X** THIS CODE COPIES KMEM VALUES INTO THE INFO STRUCTURE ASSUMING THAT
  1206. X** VALUES READ FROM THE KERNEL HAVE TYPE CADDR_T. THEREFORE, WE ARE
  1207. X** MAKING THE DUBIOUS ASSUMPTION THAT INTS, POINTERS AND CADDR_T's
  1208. X** HAVE IDENTICAL SIZES.
  1209. X*/
  1210. Xinitsymbols ()
  1211. X{
  1212. X    register struct nlist   *np ;
  1213. X    register struct symbol  *s ;
  1214. X    register struct nlist   *np0 ;
  1215. X    char                    *filesymbol ;
  1216. X# ifdef KVM
  1217. X    extern kvm_t           *Flkvm ;
  1218. X# endif
  1219. X    extern struct flags     Flg ;
  1220. X    extern struct symbol    Symbollist[] ;
  1221. X    extern struct info      Info ;
  1222. X    char                    *getcore() ;
  1223. X    char                    *strncpy() ;
  1224. X
  1225. X    filesymbol = Flg.flg_s ? Flg.flg_s : FILE_SYMBOL ;
  1226. X    /* Find the length of the symbol table */
  1227. X    for ( s = Symbollist ; s->s_kname ; s++ )
  1228. X        ;
  1229. X    /* Construct an nlist structure by copying names from the symbol table*/
  1230. X    np0 = (struct nlist*)getcore( (s-Symbollist+1)*sizeof( struct nlist ) );
  1231. X    for ( s = Symbollist, np = np0 ; s->s_kname ; s++, np++ )
  1232. X    {
  1233. X# ifdef SUN386I
  1234. X        /* Remove '_' prefix because 386i uses COFF format -
  1235. X           Provided by Martin Reed <mr@ritd.co.uk> */
  1236. X        np->n_name = &s->s_kname[1] ;       
  1237. X# else SUN386I
  1238. X                                     
  1239. X        np->n_name = s->s_kname ; 
  1240. X# endif SUN386I     
  1241. X        np[1].n_name = (char*)0 ;       
  1242. X        np->n_value = 0 ;
  1243. X    }
  1244. X# ifdef KVM
  1245. X    if ( kvm_nlist( Flkvm, np0 ) == -1 )
  1246. X    {
  1247. X        fprintf( stderr, "sps - Can't read symbol file %s", filesymbol);
  1248. X        sysperror() ;
  1249. X    }
  1250. X              
  1251. X# else KVM
  1252. X#  ifdef BSD42
  1253. X    if ( access( filesymbol, R_OK ) < 0 )
  1254. X#  else BSD42
  1255. X    if ( access( filesymbol, 4 ) < 0 )
  1256. X#  endif BSD42
  1257. X    {
  1258. X        fprintf( stderr, "sps - Can't open symbol file %s", filesymbol);
  1259. X        sysperror() ;
  1260. X    }
  1261. X    /* Get kernel addresses */
  1262. X    (void)nlist( filesymbol, np0 ) ;              
  1263. X    if ( np0[0].n_value == -1 )
  1264. X    {
  1265. X        fprintf( stderr, "sps - Can't read symbol file %s", filesymbol);
  1266. X        sysperror() ;
  1267. X    }
  1268. X# endif KVM
  1269. X    for ( s = Symbollist, np = np0 ; s->s_kname ; s++, np++ )
  1270. X    {                                       
  1271. X        if ( !np->n_value )             
  1272. X        {
  1273. X            fprintf( stderr, "sps - Can't find symbol %s in %s",
  1274. X                np->n_name, filesymbol ) ;
  1275. X            /* Assume this error to be unimportant if the address
  1276. X               is only associated with a process wait state.
  1277. X               This may happen if the system has been configured
  1278. X               without a particular device. */
  1279. X            fprintf( stderr, &Info.i_waitstate[ 0 ] <= s->s_info
  1280. X                && s->s_info < &Info.i_waitstate[ NWAITSTATE ]
  1281. X                ? " (error is not serious)\n"
  1282. X                : " (ERROR MAY BE SERIOUS)\n" ) ;
  1283. X            *s->s_info = (caddr_t)0 ;
  1284. X            continue ;
  1285. X        }
  1286. X        /* If no indirection is required, just copy the obtained value
  1287. X           into the `Info' structure. */
  1288. X        if ( !s->s_indirect )           
  1289. X        {                               
  1290. X        /* DUBIOUS ASSUMPTION THAT KMEM VALUE HAS SIZE OF A CADDR_T */
  1291. X            *s->s_info = (caddr_t)np->n_value ;
  1292. X            continue ;              
  1293. X        }                               
  1294. X        /* Otherwise one level of indirection is required. Using the
  1295. X           obtained address, look again in the kernel for the value */
  1296. X        /* DUBIOUS ASSUMPTION THAT KMEM VALUE HAS SIZE OF A CADDR_T */
  1297. X        (void)getkmem( (long)np->n_value, (char*)s->s_info,
  1298. X            sizeof(caddr_t) ) ;
  1299. X    }
  1300. X    free( (char*)np0 ) ;
  1301. X}
  1302. END_OF_FILE
  1303.   if test 3515 -ne `wc -c <'initsymbols.c'`; then
  1304.     echo shar: \"'initsymbols.c'\" unpacked with wrong size!
  1305.   fi
  1306.   # end of 'initsymbols.c'
  1307. fi
  1308. if test -f 'mktree.c' -a "${1}" != "-c" ; then 
  1309.   echo shar: Will not clobber existing file \"'mktree.c'\"
  1310. else
  1311.   echo shar: Extracting \"'mktree.c'\" \(1703 characters\)
  1312.   sed "s/^X//" >'mktree.c' <<'END_OF_FILE'
  1313. X# ifndef lint
  1314. Xstatic char SccsId[] =  "@(#)mktree.c    1.1\t10/1/88" ;
  1315. X# endif
  1316. X
  1317. X# include       "sps.h"
  1318. X
  1319. X/*
  1320. X** MKTREE - Sort the needed processes by subtree and at the top by user.
  1321. X** This procedure takes a list of processes (as returned by needed())
  1322. X** and returnes a pointer to a sorted list.
  1323. X*/
  1324. Xstruct process  *mktree ( process, plist )
  1325. X
  1326. Xstruct process                  *process ;
  1327. Xstruct process                  *plist ;
  1328. X
  1329. X{
  1330. X    register struct process *p ;
  1331. X    register struct process *pp ;
  1332. X    register struct process *lp ;
  1333. X    struct process          *op ;
  1334. X    struct process          proot ;
  1335. X
  1336. X    proot.pr_sibling = (struct process*)0 ;
  1337. X    for ( p = plist ; p ; p = p->pr_plink )
  1338. X    {
  1339. X        if ( p->pr_pptr > &process[1] )
  1340. X        {
  1341. X            for ( pp = plist ; pp ; pp = pp->pr_plink )
  1342. X            {
  1343. X                if ( pp != p->pr_pptr )
  1344. X                    continue ;
  1345. X                if ( lp = pp->pr_child )
  1346. X                {       /* Does process have children ? */
  1347. X                    op = (struct process*)0 ;
  1348. X                    while (lp &&
  1349. X                    lp->pr_p.p_pid < p->pr_p.p_pid )
  1350. X                    {
  1351. X                        op = lp ;
  1352. X                        lp=lp->pr_sibling ;
  1353. X                    }
  1354. X                    if ( op )
  1355. X                    {
  1356. X                        p->pr_sibling = lp ;
  1357. X                        op->pr_sibling = p ;
  1358. X                        break ;
  1359. X                    }
  1360. X                }       
  1361. X                p->pr_sibling = lp ;
  1362. X                pp->pr_child = p ;
  1363. X                break ;
  1364. X            }
  1365. X            if ( pp )
  1366. X                continue ;
  1367. X        }
  1368. X        /* We have a top level process, sort into top level list.
  1369. X           The top level is sorted firstly by user-id and then
  1370. X           by process-id. */
  1371. X        lp = &proot ;
  1372. X        pp = lp->pr_sibling ;
  1373. X        while ( pp )
  1374. X        {
  1375. X            if ( p->pr_p.p_uid < pp->pr_p.p_uid )
  1376. X                break ;
  1377. X            if ( p->pr_p.p_uid == pp->pr_p.p_uid
  1378. X            && p->pr_p.p_pid < pp->pr_p.p_pid )
  1379. X                break ;
  1380. X            lp = pp, pp = pp->pr_sibling ;
  1381. X        }
  1382. X        p->pr_sibling = lp->pr_sibling ;
  1383. X        lp->pr_sibling = p ;
  1384. X    }
  1385. X    return ( proot.pr_sibling ) ;
  1386. X}
  1387. END_OF_FILE
  1388.   if test 1703 -ne `wc -c <'mktree.c'`; then
  1389.     echo shar: \"'mktree.c'\" unpacked with wrong size!
  1390.   fi
  1391.   # end of 'mktree.c'
  1392. fi
  1393. if test -f 'percentmem.c' -a "${1}" != "-c" ; then 
  1394.   echo shar: Will not clobber existing file \"'percentmem.c'\"
  1395. else
  1396.   echo shar: Extracting \"'percentmem.c'\" \(1112 characters\)
  1397.   sed "s/^X//" >'percentmem.c' <<'END_OF_FILE'
  1398. X# ifndef lint
  1399. Xstatic char SccsId[] =  "@(#)percentmem.c    1.1\t10/1/88" ;
  1400. X# endif
  1401. X
  1402. X# include       "sps.h"
  1403. X# ifndef SUNOS40
  1404. X# include       <h/text.h>
  1405. X# endif
  1406. X# ifdef BSD42
  1407. X# include    <machine/pte.h>
  1408. X# else
  1409. X# include       <h/pte.h>
  1410. X# include       <h/vmparam.h>
  1411. X# endif
  1412. X# include       <h/vmmac.h>
  1413. X
  1414. X/* PERCENTMEM - Returns the percentage of real memory used by this process */
  1415. Xdouble  percentmem ( p )
  1416. X
  1417. Xregister struct process         *p ;
  1418. X
  1419. X{
  1420. X# ifndef SUNOS40
  1421. X    register struct text    *tp ;
  1422. X# endif
  1423. X    int                     szptudot ;
  1424. X    double                  fracmem ;
  1425. X    extern struct info      Info ;
  1426. X
  1427. X# ifdef SUNOS40
  1428. X    if ( !(p->pr_p.p_flag & SLOAD) )
  1429. X        return ( 0.0 ) ;
  1430. X    szptudot = UPAGES ;
  1431. X    fracmem = ( (double)p->pr_p.p_rssize + szptudot ) ;
  1432. X# else
  1433. X    tp = p->pr_p.p_textp ;
  1434. X    if ( !(p->pr_p.p_flag & SLOAD) || !tp )
  1435. X        return ( 0.0 ) ;
  1436. X    szptudot = UPAGES + clrnd( ctopt( p->pr_p.p_dsize + p->pr_p.p_ssize ) );
  1437. X    fracmem = ( (double)p->pr_p.p_rssize + szptudot ) / CLSIZE ;
  1438. X    if ( tp->x_ccount )
  1439. X        fracmem += ((double)tp->x_rssize)/CLSIZE/tp->x_ccount ;
  1440. X# endif
  1441. X    return ( 100.0 * fracmem / (double)Info.i_ecmx ) ;
  1442. X}
  1443. END_OF_FILE
  1444.   if test 1112 -ne `wc -c <'percentmem.c'`; then
  1445.     echo shar: \"'percentmem.c'\" unpacked with wrong size!
  1446.   fi
  1447.   # end of 'percentmem.c'
  1448. fi
  1449. if test -f 'prcpu.c' -a "${1}" != "-c" ; then 
  1450.   echo shar: Will not clobber existing file \"'prcpu.c'\"
  1451. else
  1452.   echo shar: Extracting \"'prcpu.c'\" \(1614 characters\)
  1453.   sed "s/^X//" >'prcpu.c' <<'END_OF_FILE'
  1454. X# ifndef lint
  1455. Xstatic char SccsId[] =  "@(#)prcpu.c    1.1\t10/1/88" ;
  1456. X# endif
  1457. X
  1458. X# include       "sps.h"
  1459. X
  1460. X# ifdef BSD42
  1461. X
  1462. X/* PRCPU - Print cpu time */
  1463. Xprcpu ( time, utime )
  1464. X
  1465. Xregister time_t                 time ;
  1466. Xtime_t                          utime ;
  1467. X
  1468. X{
  1469. X    time += utime / 1000000 ;
  1470. X    utime %= 1000000 ;
  1471. X    if ( time < 0L )
  1472. X    {       /* Ignore negative times */
  1473. X        printf( "     " ) ;     
  1474. X        return ;
  1475. X    }
  1476. X    if ( time < 60L*10L )
  1477. X    {       /* Print as seconds if less than 1000 seconds */
  1478. X        printf( "%3d.%1d", (int)time, (int)utime/100000 ) ;
  1479. X        return ;
  1480. X    }
  1481. X    /* Print as minutes if less than 10 hours ; print as hours if less than
  1482. X       10 days, else print as days. */
  1483. X    if ( time < 60L*60L*10L )               
  1484. X        printf( "%3D M", time/60L ) ;
  1485. X    else if ( time < 24L*60L*60L*10L )
  1486. X        printf( "%3D H", time/60L/60L ) ;
  1487. X    else
  1488. X        printf( "%3D D", time/60L/60L/24L ) ;
  1489. X}
  1490. X
  1491. X# else
  1492. X
  1493. X/* PRCPU - Print cpu time */
  1494. Xprcpu ( time )
  1495. X
  1496. Xregister time_t                 time ;
  1497. X
  1498. X{
  1499. X    extern struct info      Info ;
  1500. X
  1501. X    if ( time < 0L )
  1502. X    {       /* Ignore negative times */
  1503. X        printf( "     " ) ;     
  1504. X        return ;
  1505. X    }
  1506. X    if ( time < Info.i_hz*60L*10L )
  1507. X    {       /* Less than 10 minutes */
  1508. X        printf( "%3D.%1D", time/Info.i_hz,
  1509. X            (time % Info.i_hz / (Info.i_hz/10L)) ) ;
  1510. X        return ;
  1511. X    }
  1512. X    /* If less than 10 hours, print as minutes */
  1513. X    time /= Info.i_hz ;
  1514. X    /* Print as minutes if less than 10 hours ; print as hours if less than
  1515. X       10 days, else print as days. */
  1516. X    if ( time < 60L*60L*10L )               
  1517. X        printf( "%3D M", time/60L ) ;
  1518. X    else if ( time < 24L*60L*60L*10L )
  1519. X        printf( "%3D H", time/60L/60L ) ;
  1520. X    else
  1521. X        printf( "%3D D", time/60L/60L/24L ) ;
  1522. X}
  1523. X
  1524. X# endif
  1525. END_OF_FILE
  1526.   if test 1614 -ne `wc -c <'prcpu.c'`; then
  1527.     echo shar: \"'prcpu.c'\" unpacked with wrong size!
  1528.   fi
  1529.   # end of 'prcpu.c'
  1530. fi
  1531. if test -f 'readstatus.c' -a "${1}" != "-c" ; then 
  1532.   echo shar: Will not clobber existing file \"'readstatus.c'\"
  1533. else
  1534.   echo shar: Extracting \"'readstatus.c'\" \(1281 characters\)
  1535.   sed "s/^X//" >'readstatus.c' <<'END_OF_FILE'
  1536. X# ifndef lint
  1537. Xstatic char SccsId[] =  "@(#)readstatus.c    1.1\t10/1/88" ;
  1538. X# endif
  1539. X
  1540. X# include       "sps.h"
  1541. X# ifndef SUNOS40
  1542. X# include       <h/text.h>
  1543. X# endif
  1544. X
  1545. X/* READSTATUS - Reads the kernel memory for current processes and texts */
  1546. X# ifdef SUNOS40
  1547. Xreadstatus ( process )
  1548. X
  1549. Xregister struct process         *process ;
  1550. X
  1551. X# else
  1552. X
  1553. Xreadstatus ( process, text )
  1554. X
  1555. Xregister struct process         *process ;
  1556. Xstruct text                     *text ;
  1557. X
  1558. X# endif
  1559. X{
  1560. X    register struct proc    *p ;
  1561. X    register struct proc    *p0 ;
  1562. X    register struct process *pr ;
  1563. X    int                     size ;
  1564. X    extern struct info      Info ;
  1565. X    char                    *getcore() ;
  1566. X
  1567. X# ifndef SUNOS40
  1568. X    /* Read current text information */
  1569. X    size = Info.i_ntext * sizeof( struct text ) ;
  1570. X    if ( getkmem( (long)Info.i_text0, (char*)text, size ) != size )
  1571. X        prexit( "sps - Can't read system text table\n" ) ;
  1572. X# endif
  1573. X    /* Read current process information */
  1574. X    size = Info.i_nproc * sizeof( struct proc ) ;
  1575. X    p0 = (struct proc*)getcore( size ) ;
  1576. X    if ( getkmem( (long)Info.i_proc0, (char*)p0, size ) != size )
  1577. X        prexit( "sps - Can't read system process table\n" ) ;
  1578. X    /* Copy process information into our own array */
  1579. X    for ( p = p0, pr = process ; pr < &process[ Info.i_nproc ] ; p++, pr++ )
  1580. X        pr->pr_p = *p ;
  1581. X    free( (char*)p0 ) ;
  1582. X}
  1583. END_OF_FILE
  1584.   if test 1281 -ne `wc -c <'readstatus.c'`; then
  1585.     echo shar: \"'readstatus.c'\" unpacked with wrong size!
  1586.   fi
  1587.   # end of 'readstatus.c'
  1588. fi
  1589. if test -f 'selectproc.c' -a "${1}" != "-c" ; then 
  1590.   echo shar: Will not clobber existing file \"'selectproc.c'\"
  1591. else
  1592.   echo shar: Extracting \"'selectproc.c'\" \(2248 characters\)
  1593.   sed "s/^X//" >'selectproc.c' <<'END_OF_FILE'
  1594. X# ifndef lint
  1595. Xstatic char SccsId[] =  "@(#)selectproc.c    1.2\t6/15/90" ;
  1596. X# endif
  1597. X
  1598. X# include       "sps.h"
  1599. X# include       "flags.h"
  1600. X# ifdef USELOGINUID
  1601. X# include    <pwd.h>
  1602. X# endif USELOGINUID
  1603. X
  1604. X/*
  1605. X** SELECTPROC - Given a process structure, this procedure decides whether
  1606. X** the process is a candidate for printing.
  1607. X*/
  1608. Xselectproc ( p, process, thisuid )
  1609. X
  1610. Xregister struct process         *p ;            
  1611. Xregister struct process         *process ;      
  1612. Xint                thisuid ;
  1613. X
  1614. X{
  1615. X    register union flaglist *fp ;
  1616. X    register struct process *pp ;
  1617. X#ifdef USELOGINUID
  1618. X    char            *username ;
  1619. X    struct passwd        *pw ;
  1620. X    char            *getlogin() ;
  1621. X    struct passwd        *getpwnam() ;
  1622. X#endif USELOGINUID
  1623. X    extern struct flags     Flg ;
  1624. X
  1625. X    /* Flg.flg_AZ is an internal flag set if one of flags `A' to `Z'
  1626. X       was specified. If this is not set, a process is listed only
  1627. X       if it or one of its ancestors belongs to the invoking user. */
  1628. X    if ( !Flg.flg_AZ )
  1629. X    {
  1630. X#ifdef USELOGINUID
  1631. X        thisuid = (username = getlogin())
  1632. X            && (pw = getpwnam( username )) ? pw->pw_uid : getuid() ;
  1633. X#endif USELOGINUID
  1634. X        for ( pp = p ; pp > &process[1] ; pp = pp->pr_pptr )
  1635. X            if ( thisuid == pp->pr_p.p_uid )
  1636. X                return ( 1 ) ;
  1637. X    }
  1638. X    if ( Flg.flg_A )
  1639. X        return ( 1 ) ;
  1640. X    if ( Flg.flg_P )
  1641. X        for ( fp = Flg.flg_Plist ; fp->f_pid >= 0 ; fp++ )
  1642. X            if ( fp->f_pid == p->pr_p.p_pid )
  1643. X                return ( 1 ) ;
  1644. X    if ( Flg.flg_U )
  1645. X        for ( pp = p ; pp > &process[1] ; pp = pp->pr_pptr )
  1646. X            for ( fp = Flg.flg_Ulist ; fp->f_uid >= 0 ; fp++ )
  1647. X                if ( fp->f_uid == pp->pr_p.p_uid )
  1648. X                    return ( 1 ) ;
  1649. X    switch ( p->pr_p.p_stat )
  1650. X    {
  1651. X        case SRUN :
  1652. X            if ( Flg.flg_B )
  1653. X# ifdef SUNOS40
  1654. X                /* Ignore the idle processes */
  1655. X                return ( p->pr_p.p_pid != 3
  1656. X                    && p->pr_p.p_pid != 4 ) ;
  1657. X# else
  1658. X                return ( 1 ) ;
  1659. X# endif SUNOS40
  1660. X            break ;
  1661. X        case SSLEEP :
  1662. X            if ( Flg.flg_B
  1663. X            &&   p->pr_p.p_pri < PZERO && p->pr_p.p_pid > MSPID )
  1664. X# ifdef SUNOS40
  1665. X                /* Ignore the idle processes */
  1666. X                return ( p->pr_p.p_pid != 3
  1667. X                    && p->pr_p.p_pid != 4 ) ;
  1668. X# else
  1669. X                return ( 1 ) ;
  1670. X# endif SUNOS40
  1671. X        case SWAIT :
  1672. X        case SIDL :
  1673. X            if ( Flg.flg_W )
  1674. X                return ( 1 ) ;
  1675. X            break ;
  1676. X        case SSTOP :
  1677. X            if ( Flg.flg_S )
  1678. X                return ( 1 ) ;
  1679. X            break ;
  1680. X        case SZOMB :
  1681. X            if ( Flg.flg_Z )
  1682. X                return ( 1 ) ;
  1683. X            break ;
  1684. X        default :
  1685. X            break ;
  1686. X    }
  1687. X    return ( 0 ) ;
  1688. X}
  1689. END_OF_FILE
  1690.   if test 2248 -ne `wc -c <'selectproc.c'`; then
  1691.     echo shar: \"'selectproc.c'\" unpacked with wrong size!
  1692.   fi
  1693.   # end of 'selectproc.c'
  1694. fi
  1695. if test -f 'termwidth.c' -a "${1}" != "-c" ; then 
  1696.   echo shar: Will not clobber existing file \"'termwidth.c'\"
  1697. else
  1698.   echo shar: Extracting \"'termwidth.c'\" \(978 characters\)
  1699.   sed "s/^X//" >'termwidth.c' <<'END_OF_FILE'
  1700. X# ifndef lint
  1701. Xstatic char SccsId[] =  "@(#)termwidth.c    1.3\t8/6/90" ;
  1702. X# endif
  1703. X
  1704. X# include    <sys/ioctl.h>
  1705. X
  1706. X/*
  1707. X** TERMWIDTH - Sets the external variable `Termwidth' to the # of columns
  1708. X** on the terminal.
  1709. X*/
  1710. Xtermwidth ()
  1711. X{
  1712. X    register char           *termtype ;
  1713. X    register int            twidth ;
  1714. X# ifdef TIOCGWINSZ
  1715. X    struct winsize        w ;
  1716. X# else
  1717. X# ifdef TIOCGSIZE
  1718. X    struct ttysize          w ;
  1719. X# endif
  1720. X# endif
  1721. X    char                    buf[ 1025 ] ;
  1722. X    extern unsigned         Termwidth ;
  1723. X    char                    *getenv() ;
  1724. X
  1725. X# ifdef TIOCGWINSZ
  1726. X    w.ws_col = 0 ;
  1727. X    if ( !ioctl( 0, TIOCGWINSZ, &w ) && w.ws_col )
  1728. X    {
  1729. X        Termwidth = w.ws_col ;
  1730. X        return ;
  1731. X    }
  1732. X# else
  1733. X# ifdef TIOCGSIZE
  1734. X    w.ts_cols = 0 ;
  1735. X    if ( !ioctl( 0, TIOCGSIZE, &w ) && w.ts_cols )
  1736. X    {
  1737. X        Termwidth = w.ts_cols ;
  1738. X        return ;
  1739. X    }
  1740. X# endif
  1741. X# endif
  1742. X    Termwidth = 80 ;
  1743. X    if ( !(termtype = getenv( "TERM" )) )
  1744. X        return ;
  1745. X    if ( tgetent( buf, termtype ) != 1 )
  1746. X        return ;
  1747. X    twidth = tgetnum( "co" ) ;
  1748. X    if ( twidth > 40 )
  1749. X        Termwidth = twidth ;
  1750. X}
  1751. END_OF_FILE
  1752.   if test 978 -ne `wc -c <'termwidth.c'`; then
  1753.     echo shar: \"'termwidth.c'\" unpacked with wrong size!
  1754.   fi
  1755.   # end of 'termwidth.c'
  1756. fi
  1757. if test -f 'vmstat.c' -a "${1}" != "-c" ; then 
  1758.   echo shar: Will not clobber existing file \"'vmstat.c'\"
  1759. else
  1760.   echo shar: Extracting \"'vmstat.c'\" \(1902 characters\)
  1761.   sed "s/^X//" >'vmstat.c' <<'END_OF_FILE'
  1762. X# ifndef lint
  1763. Xstatic char SccsId[] =  "@(#)vmstat.c    1.1\t10/1/88" ;
  1764. X# endif
  1765. X
  1766. X# ifdef SUNOS40
  1767. X# ifndef OLDSTATS
  1768. X# include "sps.h"
  1769. X# include <h/mman.h>
  1770. X# include <vm/hat.h>
  1771. X# include <vm/as.h>
  1772. X# include <vm/seg.h>
  1773. X# include <vm/seg_vn.h>
  1774. X
  1775. Xseg_count ( p )
  1776. X
  1777. Xstruct process                  *p ;
  1778. X
  1779. X{
  1780. X    extern struct info      Info ;
  1781. X    struct as               as ;        /* address space */
  1782. X    struct seg              seg ;        /* segment in addr space */
  1783. X    struct segvn_data       vn_data ;
  1784. X    unsigned                private = 0 ;
  1785. X    unsigned                shared = 0 ;
  1786. X
  1787. X    p->pr_private = 0 ;
  1788. X    p->pr_shared = 0 ;
  1789. X
  1790. X    if ( getkmem( (long)p->pr_p.p_as, &as, sizeof( as ) ) != sizeof( as ) )
  1791. X        return( -1 ) ;
  1792. X    seg.s_next = as.a_segs ;    /* setup for loop */
  1793. X    do
  1794. X    {
  1795. X        if ( ( getkmem( seg.s_next, &seg, sizeof( seg ) ) )
  1796. X        != sizeof( seg ) )
  1797. X            break ;
  1798. X        if ( seg.s_as != p->pr_p.p_as )
  1799. X            continue ;    /* invalid segment */
  1800. X        if ( seg.s_ops != Info.i_segvn_ops )
  1801. X        {            /* mapped device is "shared" */
  1802. X            shared += seg.s_size ;
  1803. X            continue ;
  1804. X        }
  1805. X        if ( getkmem( (long)seg.s_data, &vn_data, sizeof( vn_data ) )
  1806. X        != sizeof( vn_data ) )
  1807. X            continue ;
  1808. X        /*
  1809. X         * If a segment has an anonymous mapping, it is in the swap
  1810. X         * area.  If it is also MAP_PRIVATE, we consider it "private"
  1811. X         * (even though it may be shared between parent and child after
  1812. X         * a fork() call).  Segments without an anonymous mapping are
  1813. X         * considered to be "shared".  [Should we worry about swap
  1814. X         * space reserved for copy-on-write shared segments?]
  1815. X         */
  1816. X
  1817. X        if ( vn_data.amp && (vn_data.type & MAP_TYPE) == MAP_PRIVATE )
  1818. X            private += seg.s_size ;
  1819. X        else
  1820. X            shared += seg.s_size ;
  1821. X    }
  1822. X    while ( seg.s_next != as.a_segs ) ;
  1823. X
  1824. X# define BYTETOPAGE(x) (((x)+(PAGESIZE-1))>>PGSHIFT)
  1825. X
  1826. X    p->pr_private = BYTETOPAGE( private ) ;
  1827. X    p->pr_shared = BYTETOPAGE( shared ) ;
  1828. X    p->pr_p.p_rssize = as.a_rss ;    /* update count of resident pages */
  1829. X    return( 0 ) ;
  1830. X}
  1831. X# endif
  1832. X# endif
  1833. END_OF_FILE
  1834.   if test 1902 -ne `wc -c <'vmstat.c'`; then
  1835.     echo shar: \"'vmstat.c'\" unpacked with wrong size!
  1836.   fi
  1837.   # end of 'vmstat.c'
  1838. fi
  1839. echo shar: End of archive 3 \(of 4\).
  1840. cp /dev/null ark3isdone
  1841. MISSING=""
  1842. for I in 1 2 3 4 ; do
  1843.     if test ! -f ark${I}isdone ; then
  1844.     MISSING="${MISSING} ${I}"
  1845.     fi
  1846. done
  1847. if test "${MISSING}" = "" ; then
  1848.     echo You have unpacked all 4 archives.
  1849.     rm -f ark[1-9]isdone
  1850. else
  1851.     echo You still must unpack the following archives:
  1852.     echo "        " ${MISSING}
  1853. fi
  1854. exit 0
  1855. exit 0 # Just in case...
  1856.